const path = require("path");//路径包
const webpack = require("webpack");
const HtmlWebpackPlugin = require('html-webpack-plugin');//打包html模版到dist文件夹下
const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = {
    entry: {
        bundle: './src/main.js',
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js',
    },
    optimization: {
        splitChunks: {
            chunks: 'all'
        },
        usedExports: true,//负责标记没有引用的部分
        concatenateModules: true,
        minimize: true,//代码压缩，清除没有引用的部分

    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    "style-loader",
                    "css-loader",
                ]
            },
            {
                test: /\.less$/,
                use: [
                    "style-loader",
                    "css-loader",
                    "less-loader"
                ]
            },
            {
                test: /\.png$/,
                use: {
                    loader: "url-loader",
                    options: {
                        esModule: false,
                        limit: 10 * 1024
                    }
                }
            },
            {
                test: /\.vue$/,
                loader: ['vue-loader', 'eslint-loader']
            }
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({  //打包html模版用的webpack插件，html-webpack-plugin
            title: 'vue App',
            template: './public/index.html',
            templateParameters: {
                BASE_URL: '/'
            }
        }),
    ],

}